<template>
  <!-- 工单维护-已下发 -->
  <el-container class="handle-already-container">
    <!-- 顶栏容器 -->
    <el-header>
      <!-- 查询框 -->
      <div class="search-box">
        <div class="conditions-box">
          <div class="conditions-item">
            工单编号:
            <el-input
              v-model="pageParam.condition.code"
              size="small"
              :clearable="true"
              placeholder="请输入工单编号"
              style="width: 160px;"
            ></el-input>
          </div>
          <div class="conditions-item">
            来信人:
            <el-input
              v-model="pageParam.condition.income"
              size="small"
              :clearable="true"
              placeholder="请输入来信人"
              style="width: 160px;"
            ></el-input>
          </div>
          <div class="conditions-item">
            工单内容:
            <el-input
              v-model="pageParam.condition.content"
              size="small"
              :clearable="true"
              placeholder="请输入内容关键字"
              style="width: 160px;"
            ></el-input>
          </div>
          <div class="conditions-item">
            工单来源:
            <el-select
              v-model="pageParam.condition.sourceId"
              size="small"
              :clearable="true"
              placeholder="请选择工单来源"
              @change="doSearch"
              style="width: 160px;"
            >
              <el-option
                v-for="item in sourceList"
                :key="item.lyid"
                :label="item.lymc"
                :value="item.lyid"
              ></el-option>
            </el-select>
          </div>
        </div>
        <div class="search-btn">
          <el-button
            size="small"
            icon="el-icon-search"
            plain
            @click="doSearch"
            :loading="loadingTable"
            >查询</el-button
          >
        </div>
      </div>
    </el-header>
    <!-- 主要区域容器 -->
    <div class="el-main">
      <el-table
        @row-dblclick="handledbClick"
        :data="tableItem.list"
        stripe
        border
        class="table_el"
        :height="tableHeight"
        v-loading="loadingTable"
      >
        <el-table-column
          prop="isOverdue"
          label="超期"
          align="center"
          width="60"
        >
          <template slot-scope="scope">
            <i
              v-if="scope.row.isOverdue === 1"
              class="el-icon-date"
              style="color: red; font-size: 16px;"
            ></i>
            <i
              v-else-if="scope.row.isOverdue === 0"
              class="el-icon-date"
              style="color: green; font-size: 16px;"
            ></i>
          </template>
        </el-table-column>
        <el-table-column
          prop="code"
          label="工单编号"
          align="left"
          width="180"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="sourceName"
          label="来源系统"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="szxx_type_sub"
          label="工单来源"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="cateName"
          label="工单类别"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="income"
          label="来信人"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column prop="repeated" label="重复" align="center">
          <template slot-scope="scope">
            <i
              v-if="scope.row.repeated === 1"
              class="el-icon-refresh"
              style="color: red; font-size: 16px;"
            ></i>
            <i
              v-else
              class="el-icon-refresh"
              style="color: grey; font-size: 16px;"
            ></i>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="important" label="重要" align="center" width="80">
          <template slot-scope="scope">
            <i v-if="scope.row.important=== 1" class="el-icon-star-off" style="color: red; font-size: 16px;"></i>
            <i v-else class="el-icon-star-off" style="color: grey; font-size: 16px;"></i>
          </template>
        </el-table-column>
        <el-table-column prop="unsatisfy" label="不满意" align="center" width="80">
          <template slot-scope="scope">
            <i v-if="scope.row.unsatisfy=== 1" class="el-icon-circle-close-outline" style="color: red; font-size: 16px;"></i>
            <i v-else class="el-icon-circle-close-outline" style="color: grey; font-size: 16px;"></i>
          </template>
        </el-table-column>-->
        <el-table-column
          prop="handleTime"
          label="办理时间"
          align="center"
          :formatter="formatHandleDate"
        ></el-table-column>
        <el-table-column
          prop="limitTime"
          label="处理时限"
          align="center"
          :formatter="formatLimitDate"
        ></el-table-column>
        <el-table-column prop="unsatisfy" label="不满意" align="center">
          <template slot-scope="scope">
            <i
              v-if="scope.row.unsatisfy === 1"
              class="el-icon-scissors"
              style="color: red; font-size: 16px;"
            ></i>
            <i
              v-else
              class="el-icon-scissors"
              style="color: #ddd; font-size: 16px;"
            ></i>
          </template>
        </el-table-column>
        <el-table-column prop="dqzt" label="当前状态" align="center">
          <template slot-scope="scope">
            <span class="colorg tabFontSize" v-if="scope.row.dqzt === 6">{{
              comDqzt(scope.row.dqzt)
            }}</span>
            <span class="colorj tabFontSize" v-else-if="scope.row.dqzt === 7">{{
              comDqzt(scope.row.dqzt)
            }}</span>
            <span class="tabFontSize" v-else>{{
              comDqzt(scope.row.dqzt)
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="operations"
          label="操作"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <div class="chumocaozuo">
              <div @mousemove="mousemovesw(scope.row, $event)">
                <el-button
                  v-for="(item, index) in scope.row.operationsModelList"
                  :key="index"
                  :type="item.type"
                  plain
                  size="mini"
                  :icon="item.icon"
                  v-bind:class="'operations-' + item.handleMethod"
                  @click="operationClick(item.handleMethod, scope.row)"
                  >{{ item.label }}
                </el-button>
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div id="tableboxwidth">
        <div
          id="chumo_s"
          :style="styleObject"
          @mouseleave="mouseleavesw"
          v-if="mousemove_data != ''"
        >
          <div id="htmlV" v-html="mousemove_data"></div>
          <div class="fuzhic">
            <el-button type="success" size="mini" @click="btn_fuzhi"
              >复制</el-button
            >
            <textarea id="input"></textarea>
          </div>
        </div>
      </div>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="tableItem.pageNum"
        :page-size="tableItem.pageSize"
        :page-sizes="[20, 30, 50, 100]"
        :total="tableItem.total"
        layout="total, sizes, prev, pager, next, jumper"
        style="float: right;"
      ></el-pagination>
    </div>

    <!-- 工单办理查看 -->
    <el-dialog
      title="工单查看"
      :visible.sync="dialogAlreadyDetail"
      width="100%"
      fullscreen
      :before-close="dialogAlreadyCloseFn"
    >
      <already-detail
        v-if="dialogAlreadyDetail"
        ref="alreadyDetail"
        v-bind:lcid="lcid"
        @dialogAlreadyCloseFn="dialogAlreadyCloseFn"
        @getAlreadyPage="getAlreadyPage"
      ></already-detail>
    </el-dialog>
  </el-container>
</template>

<script>
import alreadyDetail from './handle-already-detail.vue'

export default {
  name: 'staff-get',
  data () {
    return {
      styleObject: { top: 'none', bottom: 'none' },
      time_num: 0,
      mousemove_data: '',
      // 主键id
      wllzid: '',
      // 流程id
      lcid: '',
      // 用户信息
      userInfo: JSON.parse(sessionStorage.getItem('GOVERNANCE_USER_INFO')),
      // 来源列表
      sourceList: [],
      // 查询参数
      pageParam: {
        pageNum: 1,
        pageSize: 20,
        condition: {
          sourceId: '',
          code: '',
          income: '',
          content: '',
          deptId: '',
          empId: ''
        }
      },
      loadingTable: false,
      // 表格高度
      tableHeight: -1,
      // 表格列表
      tableItem: {},
      // 已下发查看
      dialogAlreadyDetail: false,
      fullScreen: true
    }
  },
  components: {
    alreadyDetail
  },
  created: function () {},
  mounted () {
    // window.addEventListener('mousewheel', this.handleScroll, false)
    // this.$nextTick(() => {
    //   setTimeout(() => {
    //     var box_scroll = document.getElementsByClassName('el-table__body')[1]
    //     console.log('box', box_scroll)
    //     box_scroll.addEventListener('mousewheel', this.scroll, false)
    //   }, 500)
    // })
  },
  methods: {
    // scroll (event) {
    //   console.log(event)
    //   // this.pos = event.target.scrollTop
    //   console.log('scroll', event.target.scrollTop)
    //   var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
    //   console.log(scrollTop)
    // },

    // handleScroll (e) {
    //   // 该语句可以用来判断滚轮是向上滑动还是向下
    //   var direction = e.deltaY > 0 ? 'down' : 'up'
    //   // console.log(e)
    // },

    // 鼠标移入
    mousemovesw (i, k) {
      if (this.time_num === 0) {
        this.time_num = 1
        this.mousemove_data = i.replyContent
        for (let x in this.tableItem.list) {
          if (i.wllzid == this.tableItem.list[x].wllzid) {
            setTimeout(() => {
              let tab_clientHeight = document.getElementById('tableboxwidth')
                .clientHeight
              let htm_clientHeight = document.getElementById('chumo_s')
                .scrollHeight
              if ((x - 0) * 45 + htm_clientHeight > tab_clientHeight) {
                this.styleObject.top = 'unset'
                this.styleObject.bottom = '0px'
              } else {
                this.styleObject.bottom = 'unset'
                this.styleObject.top = (x - 0) * 45 + 'px'
              }
            }, 20)
          }
        }

        setTimeout(() => {
          this.time_num = 0
        }, 200)
      }
    },
    // 鼠标移出
    mouseleavesw () {
      this.mousemove_data = ''
    },
    // 点击复制
    btn_fuzhi () {
      var text = document.getElementById('htmlV').innerText
      var input = document.getElementById('input')
      input.value = text // 修改文本框的内容
      input.select() // 选中文本
      document.execCommand('copy') // 执行浏览器复制命令
      this.$message({
        message: '复制成功',
        type: 'success',
        duration: 1000
      })
      this.mousemove_data = ''
    },
    // 页面初始化方法
    initFn () {
      this.getSourceList()
      this.doSearch()
    },
    // 获取来源列表
    getSourceList () {
      this.$axios.post(this.$api.source.selector).then(rs => {
        if (rs) {
          this.sourceList = rs
        }
      })
    },
    // 查询方法
    doSearch () {
      this.loadingTable = true
      this.getAlreadyPage()
    },
    // 获取督办分页列表
    getAlreadyPage () {
      this.pageParam.condition.empId = this.userInfo.xtyhid
      this.$axios
        .post(this.$api.handle.alreadyPage, this.pageParam)
        .then(rs => {
          if (rs) {
            this.tableItem = rs
            this.loadingTable = false
          }
        })
    },
    // 分页
    handleSizeChange: function (size) {
      this.loadingTable = true
      this.pageParam.pageSize = size
      this.getAlreadyPage()
    },
    // 分页
    handleCurrentChange: function (currentPage) {
      this.loadingTable = true
      this.pageParam.pageNum = currentPage
      this.getAlreadyPage()
    },
    // 日期格式化
    formatHandleDate: function (row, column) {
      const _this = this
      var date = row.handleTime
      if (date === undefined) {
        return ''
      }
      return _this.$moment(date).format('YYYY年MM月DD日 HH时mm分')
    },
    formatLimitDate: function (row, column) {
      const _this = this
      var date = row.limitTime
      if (date === undefined) {
        return ''
      }
      return _this.$moment(date).format('YYYY年MM月DD日')
    },
    // 操作点击事件
    operationClick (method, row) {
      this.mousemove_data = ''
      switch (method) {
        case 'detail':
          this.getFn(row)
          break
      }
    },
    handledbClick (row, event, column) {
      this.getFn(row)
    },
    // 分发
    getFn: function (item) {
      console.log(item.lcid)
      this.lcid = item.lcid
      this.dialogAlreadyDetail = true
    },
    dialogAlreadyCloseFn: function () {
      this.lcid = ''
      this.dialogAlreadyDetail = false
    }
  },
  computed: {
    comDqzt () {
      return function (data) {
        let code = '待分发'
        switch (data) {
          case '2':
            code = '待分发'
            break
          case '3':
            code = '待办理'
            break
          case '4':
            code = '已办理'
            break
          case '5':
            code = '已退回'
            break
          case '6':
            code = '已结束'
            break
          case '7':
            code = '已办理审核'
            break
          case '8':
            code = '退回待审核'
            break
          case '71':
            code = '审核未通过'
            break
          default:
            code = '待分发'
            break
        }
        return code
      }
    },
  }
}
</script>
<style lang="scss">
::v-deep .el-dialog__wrapper {
  z-index: 10000;
}
.el-main {
  padding: 0px 12px 12px 12px;

  font-size: 14px;
}
#tableboxwidth {
  height: calc(100vh - 268px);
  position: absolute;
  top: 108px;
  right: 131px;
  z-index: 1000;
  width: 500px;
  #chumo_s {
    z-index: 1000;
    position: absolute;
    padding: 20px;
    right: 0px;
    background: #f1f1f1;
    width: 320px;
    color: rgb(88, 88, 88);
    word-wrap: break-word;
  }
}
.fuzhic {
  text-align: right;
  margin-top: 11px !important;
}
#input {
  // display: none;
  position: fixed;
  top: -500px;
  left: -500px;
}
::v-deep .el-dialog__close {
  font-size: 22px !important;
}
::v-deep.el-dialog__close {
  font-size: 22px !important;
}
.handle-already-container {
  .el-table {
    height: calc(100vh - 250px) !important;
    margin-bottom: 14px;
  }
  .paste-btn-div {
    margin-top: 5px;
    text-align: center;
  }
  .gdxx-div {
    outline: 1px dotted #cccccc;
    padding-top: 7px;
    margin-top: 7px;
  }
  .tabFontSize {
    font-size: 14px;
  }
}
.colorg {
  color: #67c23a;
}
.colorj {
  color: #e6a23c;
}
</style>
